//
//  EFShareSettingController.m
//  WZEfengAndEtong
//
//  Created by wanzhao on 16/3/21.
//  Copyright © 2016年 wanzhao. All rights reserved.
//

#import "EFShareSettingController.h"
#import "CUserSettingMgr.h"
#import "CUserSettingModel.h"
#import "CFolderMgr.h"
#import "EFShareSettingCell.h"

@interface EFShareSettingController ()<UITableViewDataSource, UITableViewDelegate>

StrongProperty UITableView *tableView;

StrongProperty CUserSettingMgr *setMgr;
StrongProperty CUserSettingModel *setting;
StrongProperty CAccountModel *acc;

@end

@implementation EFShareSettingController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.navigationController setNavigationBarHidden:NO];
    [self.navigationItem setHidesBackButton:YES];
    [self.navigationItem setNewTitleCenter:@"分享设置"];
    
    
    _tableView = [[UITableView alloc] init];
    _tableView.frame = CGRectMake(0, 10.0f, HARDWARE_SCREEN_WIDTH, HARDWARE_SCREEN_HEIGHT - 64.0f);
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_tableView];
    _tableView.backgroundColor = [UIColor clearColor];
    
    
    self.view.backgroundColor = RGBCOLOR(0xf3, 0xf3, 0xf3);
    self.setMgr = [[CUserSettingMgr alloc] init];
    self.setting = [self.setMgr getUserSetting];
    self.acc = [[CFolderMgr shareInstance].accMgr getRecentlyLoginAccount];
    if (self.setting == nil) {
        self.setting = [[CUserSettingModel alloc] init];
        self.setting.userCode = self.acc.userName;
        [self.setMgr insetUserWithSetting:self.setting];
    }
    
    
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
 {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */




#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return 2;
}
//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView              // Default is 1 if not implemented
//{
//    return 4;
//}
// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   EFShareSettingCell  *setCell = [EFShareSettingCell EFShareSettingCellWithTabelView:tableView];
    setCell.textLabel.text = [self titleName:indexPath];
    if (indexPath.row == 0) {
        setCell.shortlineView.hidden = NO;
        setCell.lineView.hidden = YES;
        if ([self.setting.yuLiuZiduan1 isEqualToString:@"onlyAttention"]) {
            setCell.accessoryBtn.hidden = YES;
        } else {
            setCell.accessoryBtn.hidden = NO;
        }

    } else {
        setCell.lineView.hidden = NO;
        setCell.shortlineView.hidden = YES;
        if ([self.setting.yuLiuZiduan1 isEqualToString:@"onlyAttention"]) {
            setCell.accessoryBtn.hidden = NO;
        } else {
            setCell.accessoryBtn.hidden = YES;
        }
    }
    
    return setCell;
}

-(NSString *)titleName:(NSIndexPath *)indexPath
{
    NSString *title = nil;
    
    switch (indexPath.section) {
        case 0:
        {
            switch (indexPath.row) {
                case 0:
                {
                    title = @"查看全部";
                    
                }
                    break;
                case 1:
                {
                    title = @"只看关注";
                   
                }
                     break;
                default:
                    break;
            }
        }
            break;
        default:
            break;
    }
    return title;
}




#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat height = 50.0f;
    
    return height;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.section) {
        case 0:
        {
            switch (indexPath.row) {
                case 0:
                {
                    self.setting.yuLiuZiduan1 = @"";
                    [self.setMgr updateUserSetting:self.setting];
                }
                    break;
                case 1:
                {
                    self.setting.yuLiuZiduan1 = @"onlyAttention";
                    [self.setMgr updateUserSetting:self.setting];
                }
                    break;
                default:
                    break;
            }
        }
            break;
        default:
            break;
    }
    
    [self.tableView reloadData];
}


@end
